#include "Timer.h"
#include <psputils.h>
#include "oslib/oslib.h"

Timer::Timer(float dif) {
	sceRtcGetCurrentTick(&previous);
	res = sceRtcGetTickResolution();
	this->difference = dif;
}

void Timer::startTimer() {

	this->timerStarted_ = true;

	second = 0;
}

double Timer::getTimer() {

	if (!this->timerStarted_)
		return 0;

	sceRtcGetCurrentTick(&now);

	if (((now - previous) / ((float) res)) >= difference) {
		previous = now;
		second += difference;

	}
	//oslDrawStringf(10,40,"%u",(unsigned)previous);
	//oslDrawStringf(10,60,"%u",(unsigned)now);
	//oslDrawStringf(10,80,"%d",res);

	return second;
}

void Timer::stopTimer() {
	this->timerStarted_ = false;

}
void Timer::resetTimer() {
	second = 0;
}

